package model.components.nodes.node.sdn;

import java.util.ArrayList;
import java.util.List;

import model.components.networks.virtual.VirtualNetwork;
import model.components.nodes.node.Node;
import model.components.nodes.node.virtual.VirtualNode;

public class SdnNode extends Node
{	
	private int availableCPU;
	public int getAvailableCPU(){ return availableCPU; }
	public void setAvailableCPU( int availableCPU ){ this.availableCPU = availableCPU; }

	private int availableRAM;
	public int getAvailableRAM(){ return availableRAM; }
	public void setAvailableRAM( int availableRAM ){ this.availableRAM = availableRAM; }
	
	protected int availableStorage;
	public int getAvailableStorage(){ return availableStorage; }	
	public void setAvailableStorage( int availableStorage ){ this.availableStorage = availableStorage; }
	
	private int maxVirtualNodesNumber;
	public int getMaxVirtualNodesNumber(){ return maxVirtualNodesNumber; }
	public void setMaxVirtualNodesNumber( int maxVirtualNodesNumber ){ this.maxVirtualNodesNumber = maxVirtualNodesNumber; }
	
	private int availableVirtualNodesNumber;
	public int getAvailableVirtualNodesNumber(){ return availableVirtualNodesNumber; }
	public void setAvailableVirtualNodesNumber( int availableVirtualNodesNumber ){ this.availableVirtualNodesNumber = availableVirtualNodesNumber; }
	
	private List< VirtualNode > virtualNodes;
	public List< VirtualNode > getVirtualNodes(){ return virtualNodes; }
	public void setVirtualNodes( List< VirtualNode > virtualNodes ){ this.virtualNodes = virtualNodes; }
	
	private boolean isController;
	public boolean isController(){ return isController; }
	public void setIsController( boolean isController ){ this.isController = isController; }
	
	private VirtualNetwork virtualNetworkControlled;
	public VirtualNetwork getVirtualNetworkControlled(){ return virtualNetworkControlled; }
	public void setVirtualNetworkControlled( VirtualNetwork virtualNetworkControlled ){ this.virtualNetworkControlled = virtualNetworkControlled; }
	
	public SdnNode( String networkName, String namePrefix, int number, String type, String os, int cpu, int ram, int maxVirtualNodesNumber, String greyIcon, String greenIcon, String yellowIcon, String redIcon )
	{
		super( networkName, namePrefix, number, type, os, cpu, ram, greyIcon, greenIcon, yellowIcon, redIcon );

		this.setAvailableCPU( cpu );
		this.setAvailableRAM( ram );
		this.setMaxVirtualNodesNumber( maxVirtualNodesNumber );
		this.setAvailableVirtualNodesNumber( maxVirtualNodesNumber );
		this.setVirtualNodes( new ArrayList< VirtualNode >() );
	}
	
	@Override
	public SdnNode getCopy()
	{
		return null;
	}
	
	public SdnNode getSoftCopy()
	{
		return null;
	}
	
	public void add( VirtualNode virtualNode )
	{
		this.getVirtualNodes().add( virtualNode );
	}
	
	public void remove( VirtualNode virtualNodeToRemove )
	{
		int virtualNodeIndex = -1;
		
		for( VirtualNode virtualNode: this.getVirtualNodes() )
			if( virtualNode.equals( virtualNodeToRemove ) )
				virtualNodeIndex = this.getVirtualNodes().indexOf( virtualNode );
		
		if( virtualNodeIndex != -1 )
			this.getVirtualNodes().remove( virtualNodeIndex );
	}
	
}
